package org.jash.learnmvp.news;

import org.jash.learnmvp.mvp.BasePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

public class CategoryPresenter extends BasePresenter<ConStruct.ICategoryView> implements ConStruct.ICategoryPresenter {
    private ConStruct.ICategoryModel model = new CategoryModel();
    @Override
    public void loadNewsByCategory(int type, int page, int size) {
        disposable.add(model.getNewsByCategory(type, page, size)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(res -> {
                    if (isAttach()) {
                        if (res.getCode() == 0) {
                            getWhoView().newsSuccess(res.getData());
                        } else {
                            getWhoView().failure(new RuntimeException(res.getMsg()));
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().failure(t);
                    }
                }));
    }
}
